<?php
class OPML extends DbConnector {

	public function generateOutput() {		
		$query = "SELECT tag, name FROM `pp_podcasts` ORDER BY name;";
		$res = self::$db->query($query);
		
		$output = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>
		<opml version="2.0">
			<head>
				<title>PodcastProject directory</title>
				<ownerId>'.ROOT.'</ownerId>
			</head>
			<body>'."\n";
		
		while($info = mysql_fetch_assoc($res)) {
			$output .= '<outline text="'.$info["name"].'" type="rss"
						htmlUrl="'.ROOT.'#'.$info["tag"].'"
						xmlUrl="'.ROOT.'feed/'.$info["tag"].'/">
						</outline>'."\n";
		}
		
		$output .= '</body></opml>';
		
		
		header("Content-Type: text/x-opml");
		header("Content-Disposition: attachment; filename=\"directory.opml\"");
		ob_clean();
		flush();
		
		echo $output;
	}
}

?>